package com.sharker.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sharker.R;

/**
 * 项目名称：Sharker-master
 * 类描述：
 * 创建人：${丁江楠}
 * 创建时间：2017/4/13 11:32
 * 修改人：${丁江楠}
 * 修改时间：2017/4/13 11:32
 * 修改备注：
 */
public class Toptitlebar extends RelativeLayout {

    private ImageView left_imageView;
    private TextView right_textView;
    private TextView title_textView;

    public Toptitlebar(Context context) {
        this(context,null);
    }

    public Toptitlebar(Context context, AttributeSet attrs) {
        super(context, attrs);
        View view = View.inflate(context, R.layout.title_bar, this);
        left_imageView = (ImageView) view.findViewById(R.id.title_left_imageView);
        right_textView = (TextView) view.findViewById(R.id.title_right_textView);
        title_textView = (TextView) view.findViewById(R.id.title_textView);
        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.Topbar);
        if(array!=null){
            int resourceId = array.getResourceId(R.styleable.Topbar_leftimage, R.mipmap.ic_launcher);
            left_imageView.setBackgroundResource(resourceId);
            CharSequence text = array.getText(R.styleable.Topbar_middleText);
            title_textView.setText(text);
            CharSequence text1 = array.getText(R.styleable.Topbar_rightText);
            right_textView.setText(text1);
        }
        array.recycle();
    }
    public void setrightVisiable(boolean flag){
        if(flag){
            right_textView.setVisibility(View.GONE);
        }else{
            right_textView.setVisibility(View.VISIBLE);
        }
    }
    public void setleftOnclick(OnClickListener listener){
       left_imageView.setOnClickListener(listener);
    }


}
